//index.js
//获取应用实例
const app = getApp()
const WXBizDataCrypt = require('../../utils/cryptojs-master/RdWXBizDataCrypt.js');
Page({
    mixins: [require('../../mixins/all.js')],
    data: {
        motto: 'Hello World'
    },

    onLoad: function() {

    },
    jiemi() {
        wx.login({
            success: res => {
                //发起网络请求
                wx.request({
					url: app.globalData.server_Url + 'wx_getUnionid.php',
                    data: { jscode: res.code, },
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    method: 'POST',
                    success: res =>  {
                        console.log(res.data.session_key)
                        //拿到session_key实例化WXBizDataCrypt（）这个函数在下面解密用
                        var pc = new WXBizDataCrypt('wxf8882d2559d49ba8', res.data.session_key)
                        wx.getUserInfo({
                            success: resUser =>  {
                                //拿到getUserInfo（）取得的resUser.encryptedData, resUser.iv，调用decryptData（）解密
                                var data = pc.decryptData(resUser.encryptedData, resUser.iv)
								this.setData({ motto:data.unionId }) //显示到本页面中
								console.log('解密后 unionid: ', data.unionId)
								if(!wx.getStorageSync('unionid')){
									wx.setStorageSync('unionid',data.unionId)
								}
                            },
                            fail: function(res) {
                                console.log(res)
                            }
                        })
                    },
                    fail: function(res) {},
                    complete: function(res) {}
                });
            }
        })
    },
	__jumintro(){
		wx.navigateTo({
			url: '/pages/intro/intro?service_area=777777777',
		})
	}
})